#include "redis_context_pool.h"

using namespace std;
using namespace base;

redisContext * RedisContextPool::Create(const std::string & key) {
  const static struct timeval timeout = {1, 500000 }; // 1.5 seconds
  redisContext *context = redisConnectWithTimeout((char*)"127.0.0.1", 6379, timeout);
  if (context->err) {
      cout << "Connection error: " << context->errstr << endl;
      redisFree(context);
      return NULL;
  }
  cout << "new connection established." << endl;
  return context;
}

void RedisContextPool::Destroy(redisContext * context) {
  cout << "connection destroyed." << endl;
  redisFree(context);
}


